package org.apache.oozie.tools.workflowgenerator.client.property.control;

import org.apache.oozie.tools.workflowgenerator.client.property.PropertyTable;
import org.apache.oozie.tools.workflowgenerator.client.widget.NodeWidget;

import com.google.gwt.xml.client.Text;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;

public class KillPropertyTable extends PropertyTable {

    protected Grid grid;
    protected TextBox message;

    public KillPropertyTable(NodeWidget w) {
        super(w);
        initWidget();
    }

    /**
     * Generate xml elements of kill node and attach them to xml doc
     */
    public void generateXML(Document doc, Element root, NodeWidget next) {

        Element action = doc.createElement("kill");
        root.appendChild(action);
        action.setAttribute("name", name.getText());
        Element msgele = doc.createElement("message");
        action.appendChild(msgele);
        Text msg = doc.createTextNode(message.getText());
        msgele.appendChild(msg);
    }

    /**
     * Initialize widgets shown in property table
     */
    protected void initWidget() {

        grid = new Grid(2, 2);
        this.add(grid);

        this.setAlwaysShowScrollBars(true);
        this.setSize("100%", "80%");

        // insert row for Name
        grid.setWidget(0, 0, createLabel("Name"));
        name = new TextBox();
        grid.setWidget(0, 1, formatCell(name));

        // insert row for Message
        grid.setWidget(1, 0, createLabel("Message"));
        message = new TextBox();
        grid.setWidget(1, 1, formatCell(message));

    }
}
